cc.Class({
    extends: cc.Component,
    cancelCallback: null,
    confirmCallback: null,

    fn0: null,
    fn1: null,

    properties: {
        title: cc.Label,

        text0_lbl: cc.Label,
        text1_lbl: cc.Label,
        msg: cc.Label
    },

    onLoad(){
    },

    registerEvent(){
        window.alertNode = this.node
        window.alertNode.on("alert", e => {
            this.node.active = true
        })
    },


    /*title 暂时没有实现，不用传*/
    init(info) {
        let {title, msg, confirm_fn, cancel, text0, text1, fn0, fn1} = info
        if (title) {
            this.title.string = title
        }
        this.text0_lbl.string = text0 ? text0 : '取消'
        this.text1_lbl.string = text1 ? text1 : '确定'
        if (msg) {
            this.msg.string = msg
        }
        this.fn0 = fn0;
        this.fn1 = fn1;
        this.confirmCallback = confirm_fn
    },

    confirm() {
        if (this.confirmCallback) {
            this.confirmCallback()
        }
        if (this.fn1) {
            this.fn1()
        }
        this.scheduleOnce(() => {
            this.node.active = false
        }, 0.2)

    },

    cancel() {
        if (this.fn0) {
            this.fn0()
        }
        this.scheduleOnce(() => {
            this.node.active = false
        }, 0.2)
    },
})